# originally written by Mark Royer
# modified by Joshua Belanger
#
# A simple Makefile for compiling java programs and generating the related 
# java documentation.  To compile and generate javadoc a user can simply type
# 
# make
#
# at the command line.  To remove all of the files that were built and leave
# only the source files, a user can type
#
# make clean
#
# at the command line.  For more information about Makefiles see
#
# http://www.gnu.org/software/make/manual/make.html
#
# Additional information about javadoc can be found at
#
# http://java.sun.com/j2se/javadoc/


# The top level directory
rootdir = .

# Where the generated binaries will be put
bindir = $(rootdir)/bin

# Where the generated documentation will be put
docdir = $(rootdir)/docs

# Where the source files reside
srcdir = $(rootdir)/src

# Name of class containing main
mainClass = hw01.Answers

# Name of the generated executable
execFileName = roomboss

# List of source files
sourcelist = $(shell find $(srcdir) -name '*.java' | sed "s,[.]/,,g")

CATALINA_HOME = /usr/apache/tomcat55
CATALINA_BASE = $(rootdir)/tomcat55

# project libraries
libs = $(CATALINA_HOME)/common/lib/servlet-api.jar:/usr/share/java/postgresql.jar:/opt/jdbc/postgresql-9.0-801.jdbc4.jar

# project classpath
CLASSPATH = $(bindir):$(libs)

default: all 

all:
	
	@if [ ! -d $(bindir) ]; then mkdir $(bindir); fi;
	
        # Compile source files
	@javac -cp $(CLASSPATH) -d $(bindir) $(sourcelist) 

        # Create a convenient script to execute program
	@echo "java -cp" $(CLASSPATH) $(mainClass) &gt; $(execFileName)
	# @chmod +x $(execFileName)

        # Invoke javadoc with using the list in source list
        # -d output generated documentation to docdir
        # -linksource include a link to the source in documenation
	@javadoc -d $(docdir) -linksource $(sourcelist)

clean:
        # Remove all of the binaries
	@if [ -d $(bindir) ]; then rm -r $(bindir); fi;
	@if [ -s $(execFileName) ]; then rm $(execFileName); fi;

        # Remove all of the documentation
	@if [ -d $(docdir) ]; then rm -r $(docdir); fi;